var name:String?="test1"
var age:Int?=20

// 可选值解包，和kotlin的空值判断有点像，但是没有kotlin简洁
if let name=name,
   let age=age{
    print("name is \(name) and age is \(age)")
}

//guard 关键字解包，当条件不成立时执行 guard+条件+else+代码块,必须用在方法块中

var guardStr:String?
func testGuard() {
    guard let guardStr = guardStr else {
        print("guardStr has no value")
        return
    }
    print(guardStr)
}

testGuard()

//空值合并，testAge=nil的话，就取0
var testAge:Int?
var mustHaveResult=testAge ?? 0
print("testAge is \(mustHaveResult)")

